const app = getApp();
Page({

    /** 页面的初始数据 **/
    data: {
        details: {},
    },

    /** 生命周期函数--监听页面加载 **/
    onLoad: function (options) {
        console.log(options.id);
        let id = options.id;
        this.getDetails(id);
    },
    // 获取电影详情
    getDetails(id) {
        let param = {
            id
        };
        app.get('/film/detail', param).then(res => {
            let detail = res.data;
            detail.premiereAt = this.formatDate(detail.premiereAt);
            // item 获取总的毫秒数
            console.log(res);
            this.setData({
                details: res.data
            }, () => {
                wx.hideLoading();
            })
        }).catch(err => {
            console.log(err);
        })
    },
    // 格式化时间
    formatDate(time){
        let date = new Date(time);
        let Y = date.getFullYear();
        let M = date.getMonth() + 1;
        let day = date.getDate();
        M = M < 10 ? '0' + M : M;
        day = day < 10 ? '0' + day : day;
        return `${Y}-${M}-${day}`;
    }

})